import request from '../request'

// 获取用户列表
export function getUserList(params) {
  return request({
    url: '/api/v1/User/List',
    method: 'get',
    params
  })
}

// 添加用户
export function addUser(data) {
  return request({
    url: '/api/v1/User/Add',
    method: 'post',
    data
  })
}

// 更新用户
export function updateUser(data) {
  return request({
    url: '/api/v1/User/Update',
    method: 'put',
    data
  })
}

// 删除用户
export function deleteUser(id) {
  return request({
    url: `/api/v1/User/Delete/${id}`,
    method: 'delete'
  })
}

// 批量删除用户
export function batchDeleteUser(ids) {
  return request({
    url: '/api/v1/User/BatchDelete',
    method: 'delete',
    data: { ids }
  })
}

// 更新用户状态
export function updateUserStatus(data) {
  return request({
    url: '/api/v1/User/UpdateStatus',
    method: 'put',
    data
  })
}

// 重置密码
export function resetUserPassword(id) {
  return request({
    url: `/api/v1/User/ResetPassword/${id}`,
    method: 'put'
  })
}

// 获取用户角色
export function getUserRoles(id) {
  return request({
    url: `/api/v1/User/GetRoles/${id}`,
    method: 'get'
  })
}

// 分配用户角色
export function assignUserRoles(data) {
  return request({
    url: '/api/v1/User/AssignRoles',
    method: 'post',
    data
  })
}

// 导入用户
export function importUsers(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/api/v1/User/Import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 导出用户
export function exportUsers(params) {
  return request({
    url: '/api/v1/User/Export',
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 检查用户名是否存在
export function checkusername(params) {
  return request({
    url: '/api/v1/SysUser/username',
    method: 'get',
    params
  })
}